﻿package plugin.specialActivity.ShenMiShangDian
{
    import com.core.*;
    import flash.utils.*;
    import pluginfw.nio.*;
    import pluginfw.nio.imsg.*;

    public class ShenMiShangDianHandler extends Object implements IGroupHandler
    {

        public function ShenMiShangDianHandler()
        {
            return;
        }// end function

        public function dealSimpleMessage(param1:ISimpleMessage) : void
        {
            return;
        }// end function

        public function dealBufferMessage(param1:IBufferMessage) : void
        {
            var _loc_5:int = 0;
            var _loc_6:Object = null;
            var _loc_7:Object = null;
            var _loc_9:int = 0;
            var _loc_2:* = new Object();
            var _loc_3:* = new Input(null);
            var _loc_4:* = param1.getBody();
            param1.getBody().position = 0;
            _loc_3.setBytes(_loc_4);
            var _loc_8:int = 0;
            var _loc_10:Boolean = false;
            switch(param1.getCmd())
            {
                case CMDShenMiShangDian._2GETSHOPMSG:
                {
                    _loc_5 = _loc_3.readShort();
                    _loc_2.shopList = new Array();
                    _loc_8 = 0;
                    while (_loc_8 < _loc_5)
                    {
                        
                        _loc_9 = _loc_3.readByte();
                        if (_loc_9 != 0)
                        {
                            _loc_2.shopList[_loc_8] = new Object();
                            _loc_2.shopList[_loc_8].shopid = _loc_3.readVarInt(false);
                            _loc_2.shopList[_loc_8].allbuyNum = _loc_3.readVarInt(false);
                            _loc_2.shopList[_loc_8].canbuy = _loc_3.readVarInt(false);
                        }
                        _loc_8++;
                    }
                    _loc_2.refreshtime = _loc_3.readVarInt(false);
                    ModelProxy.change("data", "shenmishangdianmsg", _loc_2);
                    ModelProxy.change("specialActivity", "updateStateChange", null);
                    break;
                }
                case CMDShenMiShangDian._4BUY:
                {
                    _loc_2.shopid = _loc_3.readVarInt(false);
                    _loc_6 = ModelProxy.getValue("data", "shenmishangdianmsg");
                    for each (_loc_7 in _loc_6.shopList)
                    {
                        
                        if (_loc_7.shopid == _loc_2.shopid)
                        {
                            _loc_7.canbuy = 1;
                            var _loc_13:* = _loc_7;
                            var _loc_14:* = _loc_7.allbuyNum + 1;
                            _loc_13.allbuyNum = _loc_14;
                            break;
                        }
                    }
                    ModelProxy.change("specialActivity", "updateStateChange", null);
                    break;
                }
                case CMDShenMiShangDian._7GETBAIFUSHOPMSG:
                {
                    _loc_5 = _loc_3.readShort();
                    _loc_2.shopList = new Array();
                    _loc_8 = 0;
                    while (_loc_8 < _loc_5)
                    {
                        
                        _loc_9 = _loc_3.readByte();
                        if (_loc_9 != 0)
                        {
                            _loc_2.shopList[_loc_8] = new Object();
                            _loc_2.shopList[_loc_8].shopid = _loc_3.readVarInt(false);
                            _loc_2.shopList[_loc_8].allbuyNum = _loc_3.readVarInt(false);
                            _loc_2.shopList[_loc_8].canbuy = _loc_3.readVarInt(false);
                        }
                        _loc_8++;
                    }
                    _loc_2.refreshtime = _loc_3.readVarInt(false);
                    ModelProxy.change("data", "baifushenmishangdianmsg", _loc_2);
                    ModelProxy.change("specialActivity", "updateStateChange", null);
                    _loc_10 = false;
                    for each (_loc_7 in _loc_2.shopList)
                    {
                        
                        if (_loc_7.canbuy == 0)
                        {
                            _loc_10 = true;
                            break;
                        }
                    }
                    ModelProxy.change("mainui", "updateHuoDongEffect", {name:"baifu", page:"shenmishangdian", state:_loc_10});
                    ModelProxy.change("specialActivity", "updateTitleAngle", {type:5, page:"shenmishangdian", state:_loc_10});
                    break;
                }
                case CMDShenMiShangDian._9BAIFUBUY:
                {
                    _loc_2.shopid = _loc_3.readVarInt(false);
                    _loc_6 = ModelProxy.getValue("data", "baifushenmishangdianmsg");
                    _loc_10 = false;
                    for each (_loc_7 in _loc_6.shopList)
                    {
                        
                        if (_loc_7.shopid == _loc_2.shopid)
                        {
                            _loc_7.canbuy = 1;
                            var _loc_13:* = _loc_7;
                            var _loc_14:* = _loc_7.allbuyNum + 1;
                            _loc_13.allbuyNum = _loc_14;
                            break;
                            continue;
                        }
                        if (_loc_7.canbuy == 0)
                        {
                            _loc_10 = true;
                        }
                    }
                    ModelProxy.change("specialActivity", "updateStateChange", null);
                    ModelProxy.change("mainui", "updateHuoDongEffect", {name:"baifu", page:"shenmishangdian", state:_loc_10});
                    ModelProxy.change("specialActivity", "updateTitleAngle", {type:5, page:"shenmishangdian", state:_loc_10});
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function dealProxyMessage(param1:IProxyMessage) : void
        {
            return;
        }// end function

    }
}
